#lang racket

(define dx 0.00001)

(define (average3 a b c) (/ (+ a b c) 3))

(define (compose f g) (lambda (x) (f (g x))))

(define (repeated f n)
  (define (iter i result)
    (if (= i n)
        result
        (iter (+ i 1) (compose f result))))
  (iter 1 f))

(define (smooth f)
  (lambda (x) (average3 (f (+ x dx)) (f x) (f (- x dx)))))

(define (n-fold-smoothed n)
  (lambda (f) ((repeated smooth n) f)))

((smooth (lambda (x) (* x x))) 3)

(((n-fold-smoothed 2) (lambda (x) (* x x))) 3)